// 这个是用来干嘛的 就是给表单提供数据的
import { reactive, ref, onMounted } from 'vue'
import { personnelReview } from '@/api/test/testModel'
import useInstance from '@/hooks/useInstance';
import { UserPage } from '@/api/user/UserModel'
import { userPageApi,taskUserUpdataApi } from '@/api/user/user'
import { EditType } from '@/type/BaseEnum'
export default function useBaseModel(getBaseline?,) {
    const { global, proxy } = useInstance()
    const PersonSetDialog = ref<{ show: (type: string, row?: any) => void }>()
    const dialogModel = reactive({
        auditorUsers: [
            {
                taskId: '',
                taskRole: '',
                userIds: [] as Array<string>
            },
            {
                taskId: '',
                taskRole: '',
                userIds: [] as Array<string>
            },
            {
                taskId: '',
                taskRole: '',
                userIds: [] as Array<string>
            },
        ]
    })
    const getUserList = reactive({
        list: [],
    })
    let searchParams = reactive<UserPage>({
        page: 1,
        size: 10,
        name: '',
        gender: '',
        state: '',
        username: ''
    })
    onMounted(() => {
        getTableList(searchParams)
    })
    const getTableList = async (searchParams) => {
        console.log('---');
        
        const res = await userPageApi(searchParams)
        if (res.code === 200) {
            getUserList.list = res.data.records
        }
    }

    const PersonSeting = async (row) => {
        PersonSetDialog?.value?.show(EditType.ADD,row)        
    }
    const saveUpData = async (value) => {
        const res = await taskUserUpdataApi(value)
        if(res.code === 200) {
            global.$message({ message: '配置成功', type: 'success' })
        }
    }

    const baseAddBtn = (id) => {
        PersonSetDialog?.value?.show(EditType.ADD, id)
    }
    return {
        dialogModel, PersonSetDialog, baseAddBtn, PersonSeting, getTableList, getUserList, saveUpData
    }
}